package com.hzlx.web;

import com.hzlx.dto.OrderRequest;
import com.hzlx.dto.OrderResponse;
import com.hzlx.dto.PageDto;
import com.hzlx.dto.ResultDto;
import com.hzlx.service.OrderService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class OrderController {
    @Resource
    OrderService orderService;
    @PostMapping("/api/order")
    @ResponseStatus(HttpStatus.CREATED)
    public ResultDto<String> create(@RequestBody OrderRequest orderRequest){
        return ResultDto.<String>builder()
                .code("ok")
                .data(orderService.create(orderRequest))
                .build();

    }
    @GetMapping("/api/order/{ownerId}/{page}/{rows}")
    public ResultDto<PageDto<OrderResponse>> find(@PathVariable("ownerId") Integer ownerId,
                                                        @PathVariable("page") Integer page,
                                                        @PathVariable("rows") Integer rows){
        PageDto<OrderResponse> pageDto=orderService.find(ownerId,page,rows);
        return ResultDto.<PageDto<OrderResponse>>builder().code("ok").data(pageDto).build();
    }
}
